<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<link rel="stylesheet"
	data-th-href="@{{path}/static/bootstrap/css/bootstrap.css(path=${#request.getContextPath()})}">
<link rel="stylesheet"
	data-th-href="@{{path}/static/bootstrap/css/bootstrap-theme.css(path=${#request.getContextPath()})}">

<link rel="stylesheet"
	th:href="@{{path}/webjars/bootstrap-select/2.0.0-beta1/dist/css/bootstrap-select.css(path=${#request.getContextPath()})}">
<link
	data-th-href="@{{path}/webjars/bootstrapvalidator/css/bootstrapValidator.css(path=${#request.getContextPath()})}"
	rel="stylesheet" />

<script type="text/javascript"
	data-th-src="@{{path}/static/bootstrap/js/jquery-3.3.1.min.js(path=${#request.getContextPath()})}"></script>

<script type="text/javascript"
	data-th-src="@{{path}/static/bootstrap/js/bootstrap.min.js(path=${#request.getContextPath()})}"></script>
<script type="text/javascript"
	th:src="@{{path}/webjars/bootstrap-select/2.0.0-beta1/dist/js/bootstrap-select.js(path=${#request.getContextPath()})}"></script>
<script type="text/javascript"
	th:src="@{{path}/webjars/bootstrap-select/2.0.0-beta1/dist/js/i18n/defaults-zh_CN.js(path=${#request.getContextPath()})}"></script>
<script
	data-th-src="@{{path}/webjars/bootstrapvalidator/js/bootstrapValidator.js(path=${#request.getContextPath()})}"></script>
<script
	data-th-src="@{{path}/webjars/bootbox/4.4.0/bootbox.js(path=${#request.getContextPath()})}"></script>
<!-- treegrid鐨刯s -->


<script
	th:src="@{{path}/static/bootstrap/js/jquery.mobile-events.min.js(path=${#request.getContextPath()})}"
	type='text/javascript'></script>
<script
	th:src='@{{path}/static/bootstrap/js/nav.js(path=${#request.getContextPath()})}'
	type='text/javascript'></script>
</head>
<style type="text/css">
h1 {
	text-align: center;
	font-size: 20px;
}

#home {
	margin-top: 10px;
	border-top: 1px solid #000000;
	text-align: center;
}

#b_home {
	height: 300px;
}
</style>
<body>
	<div class="col-md-8 col-md-offset-2">
		<h1>行政班级</h1>
		<hr />
		<form class="form-horizontal" id="myForm">
			<div class="form-group col-md-5">
				<label for="txt_dept" class="col-sm-3 control-label">学年学期</label>
				<div class="col-sm-9">
					<select class="form-control" name="schoolYear" id="schoolYear"
						data-live-search="true">

					</select>
				</div>
			</div>

			<div class="col-md-7">
				<div class="col-md-6 col-sm-6">
					<input type="radio" name="change" value="1" id="1" checked /> <label
						for="1">格式一</label>&emsp; <input type="radio" name="change"
						value="2" id="2" /> <label for="2">格式二</label>&emsp;
				</div>
				<div class="col-md-3 col-sm-3 col-md-offset-2">
					<button type="button" class="btn btn-danger" onclick="getKb()">检索</button>
				</div>

			</div>
		</form>
	</div>
	<div id="home" class="col-md-10 col-md-offset-1">
		<h1>湖北三峡职业技术学院</h1>
		<br /> <br /> <span style="float: left;">专业：[[${profesion==null?'':profesion}]]&nbsp;&nbsp;行政班级:
			[[${year==null?'':year+'级'+className}]]</span><br />
		<div id="myTable">
		</div>
	</div>

</body>

<script type="text/javascript">
	$(function() {
		var year = '[[${year}]]';
		if (year != '' && year != undefined) {
			year = parseInt(year);
			var dqYear = new Date().getFullYear();
			var num = dqYear - year;
			if (num >= 0) {
				$('#schoolYear').append('<option>' + (year) + '年秋季学期</option>');
				for (var i = 1; i <= num; i++) {
					$('#schoolYear').append(
							'<option>' + (year + i) + '年春季学期</option><option>'
									+ (year + i) + '年秋季学期</option>');
				}
			}

		}

	});
	/* 将form表单序列化成对象object*/
	$.fn.serializeObject = function() {
		var obj = new Object();
		$.each(this.serializeArray(), function(index, param) {
			if (!(param.name in obj)) {
				obj[param.name] = param.value;
			}
		});
		return obj;
	};

	function getKb() {
		var myForm = $('#myForm').serializeObject();
		if ((myForm.schoolYear == null || myForm.schoolYear == '')
				|| (myForm.change == null || myForm.change == '')) {
			bootbox.alert('参数为空？');
			return;
		}
		$
				.ajax({
					url : 'getKb',
					type : 'post',
					dataType : 'json',
					data : {
						schoolYear : myForm.schoolYear
					},
					success : function(result) {
						if (result == null || result == undefined) {
							bootbox.alert('该学期课表暂未编排');
							return;
						}
						var xq = [ '星期一', '星期二', '星期三', '星期四', '星期五', '星期六',
								'星期日' ];
						var jc = [ '1-2', '3-4', '5-6', '7-8', '9-10' ];//上课节次
						var flag = {
							xq1 : {},
							xq2 : {},
							xq3 : {},
							xq4 : {},
							xq5 : {},
							xq6 : {},
							xq7 : {}
						};
						for ( var i in result) {
							for (var j = 0; j < xq.length; j++) {
								for (var k = 0; k < jc.length; k++) {
									if (result[i].jcb.xq == xq[j]
											&& result[i].jcb.jcsj == jc[k]) {
										eval('flag.' + xqToDm(xq[j]) + '.'
												+ jcToDm(jc[k]) + '=result[i]');
									}
								}
							}
						}
						var flagLength = 0;//取得一周上课几天
						for ( var i in flag) {
							if (Object.keys(flag[i]) != 0) {
								flagLength += 1;
							}
						}

						/* 画表 */
						if (myForm.change == '1') {
							var headStr = '<table id="aaa" class="table table-bordered table-striped table-hover table-condensed"><tr><td>星期</td><td>课程</td><td>考核方式</td><td>教师</td><td>上课班号</td><td>周次</td><td>节次</td><td>地点</td></tr></table>';
							$('#myTable').html(headStr);
							//console.log(flag);//调试用
							for (var i = 0; i < xq.length; i++) {
								for (var j = 0; j < jc.length; j++) {
									var dqFlag = eval('flag.' + xqToDm(xq[i])
											+ '.' + jcToDm(jc[j]));
									if (dqFlag == null) {
										continue;
									}
									//console.log(dqFlag); //调试用
									if (Object.keys(dqFlag) != 0) {
										$('#aaa').append(
												'<tr><td>' + dqFlag.xq
														+ '</td><td>'
														+ dqFlag.kcmc
														+ '</td><td>'
														+ dqFlag.khfs
														+ '</td><td>'
														+ dqFlag.teacherName
														+ '</td><td>'
														+ dqFlag.ep.bj
														+ '</td><td>'
														+ dqFlag.zc
														+ '</td><td>'
														+ dqFlag.skjc
														+ '</td><td>'
														+ dqFlag.dd
														+ '</td></tr>');

									}

								}

							}
							$("#myTable").trigger("create");
						} else if (myForm.change == '2') {
							var tableStr = '<table class="table table-bordered text-center"><thead><tr> <th colspan="2" class="text-center">时间/节数</th><th class="text-center">星期一</th><th class="text-center">星期二</th><th class="text-center">星期三</th><th class="text-center">星期四</th><th class="text-center">星期五</th><th class="text-center">星期六</th><th class="text-center">星期日</th> </tr> </thead><tbody id="bbb"></tbody></table>';
							$('#myTable').html(tableStr);
							$('#bbb')
									.append(
											'<tr id="sw"><td rowspan="2">上<br />午</td><td>一</td></tr>');
							for (var j = 0; j < xq.length; j++) {
								var dqFlag = eval('flag.' + xqToDm(xq[j]) + '.'
										+ jcToDm(jc[0]));
								if (dqFlag == null) {
									$('#sw').append('<td></td>');
									continue;
								}
								//console.log(dqFlag);
								$('#sw').append(
										'<td>' + dqFlag.kcmc + '<br />'
												+ dqFlag.teacherName + '<br />'
												+ dqFlag.dd + '</td>');
							}

							$('#bbb').append('<tr id="sw2"><td>二</td></tr>');
							for (var j = 0; j < xq.length; j++) {
								var dqFlag = eval('flag.' + xqToDm(xq[j]) + '.'
										+ jcToDm(jc[1]));
								if (dqFlag == null) {
									$('#sw2').append('<td></td>');
									continue;
								}
								$('#sw2').append(
										'<td>' + dqFlag.kcmc + '<br />'
												+ dqFlag.teacherName + '<br />'
												+ dqFlag.dd + '</td>');
							}

							$('#bbb')
									.append(
											'<tr id="xw"><td rowspan="2">下<br />午</td><td>三</td></tr>');
							for (var j = 0; j < xq.length; j++) {
								var dqFlag = eval('flag.' + xqToDm(xq[j]) + '.'
										+ jcToDm(jc[3]));
								if (dqFlag == null) {
									$('#xw').append('<td></td>');
									continue;
								}
								//console.log(dqFlag);
								$('#xw').append(
										'<td>' + dqFlag.kcmc + '<br />'
												+ dqFlag.teacherName + '<br />'
												+ dqFlag.dd + '</td>');
							}

							$('#bbb').append('<tr id="xw2"><td>四</td></tr>');
							for (var j = 0; j < xq.length; j++) {
								var dqFlag = eval('flag.' + xqToDm(xq[j]) + '.'
										+ jcToDm(jc[3]));
								if (dqFlag == null) {
									$('#xw2').append('<td></td>');
									continue;
								}
								$('#xw2').append(
										'<td>' + dqFlag.kcmc + '<br />'
												+ dqFlag.teacherName + '<br />'
												+ dqFlag.dd + '</td>');
							}

							$("#myTable").trigger("create");

						}
					}
				})

	};
	/* 星期转代号 */
	function xqToDm(xq) {
		if (xq == '星期一') {
			return 'xq1';
		}
		if (xq == '星期二') {
			return 'xq2';
		}
		if (xq == '星期三') {
			return 'xq3';
		}
		if (xq == '星期四') {
			return 'xq4';
		}
		if (xq == '星期五') {
			return 'xq5';
		}
		if (xq == '星期六') {
			return 'xq6';
		}
		if (xq == '星期日') {
			return 'xq7';
		}
		return 'error';
	};

	/* 节次转代号 */
	function jcToDm(jc) {
		if (jc == '1-2') {
			return 'a';
		}
		if (jc == '3-4') {
			return 'b';
		}
		if (jc == '5-6') {
			return 'c';
		}
		if (jc == '7-8') {
			return 'd';
		}
		if (jc == '9-10') {
			return 'e';
		}
		return 'error';
	};
	
	
	
</script>
</html>